<template>
    <div class="row">
        <div class="col-4 mb-4 text-center" v-for="column in listColumns" :key="column._id">
            <div class="card h-100 shadow-sm">
                <div class="card-body">
                    <img :src="column.avatar?.fitUrl" class="rounded-circle my-3" :alt="column.title">
                    <h5 class="card-title">{{ column.title }}</h5>
                    <p class="card-text text-start">{{ column.description }}</p>
                    <RouterLink :to="`column/${column._id}`" class="btn btn-outline-primary">进入专题</RouterLink>
                </div>
            </div>
        </div>
    </div>
</template>

<script setup lang="ts">
import { computed, PropType } from 'vue'
import { ColumnProps } from '../store'
import { addColumnAvatar } from '../helper'

const props = defineProps({
    columns: {
        type: Array as PropType<ColumnProps[]>,
        required: true
    }
})

const listColumns = computed(() => {
    return props.columns.map(column => {
        addColumnAvatar(column, 50, 50)
        return column
    })
})
</script>

<style scoped>
.card-body img {
    width: 50px;
    height: 50px;
}
</style>